<?php
class NewsHomeForm extends Form
{
	function __construct()
	{				
		Form::Form('NewsHomeForm');
		
		CGlobal::$website_title = 'Tin tức';
	}
	
	function draw()
	{
		global $display;
		
		$home_newss = array();
		
		$display->add('is_admin',User::have_permit(ADMIN_NEWS));
		
		$display->add('url_home',WEB_DIR);
		
		$display->add('time_now',News::displayTime());
		
		$one_cart = '';
		
		AZLib::getNewsCats();
		
		if(CGlobal::$allNewsCategories)
		{
			foreach(CGlobal::$allNewsCategories as $news_catid => $news_cat)
			{
				if($news_cat['public'])
				{
					$newss =array();
					
					$re = DB::query("SELECT * FROM news WHERE status=1 AND news_catid=$news_catid ORDER BY id DESC LIMIT 0,4");
					
					if($re)
					{
						$i=1;
						
						while($news = mysql_fetch_assoc($re))
						{
							if($i==1)
							{
								if($news['image'])
								{
									
									$news['image'] = AZLib::getImageThumb($news['image'],150,0,0,$news['img_server']);
								}
								$i++;
							}
								
							$news['url'] = URL::build('news_detail',array('news_catid'=>$news['news_catid'],'news_id'=>$news['id'],'azname'=>AZLib::safe_title($news['title'])));
							
							$news['news_h'] = date('H:i',$news['time_created']);
							$news['news_d'] = date('d-m-Y',$news['time_created']);
							
							$newss[$news['id']] = $news;
						}
						
					}
					
					if($newss)
					{
						$home_newss[$news_catid] = array(	
														'name' 	=> $news_cat['name'],
														'url' 	=> URL::build('news_list',array('news_catid'=>$news_catid,'azname'=>AZLib::safe_title($news_cat['name']))),
														'newss' => $newss
														);
					}
				}
			}
		}
		
		$display->add('home_newss',$home_newss);
		
		$display->output("NewsHome");
	}
}
?>